<?php

namespace app\user\controller\tree\config;

use app\BaseController;
use app\model\tree\TreeUserInfoModel;
use think\App;

class Info extends BaseController
{
    protected $mode;
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->mode = new TreeUserInfoModel();
    }

    /**
     * 智慧果收发设置-信息
     * @return bool|string
     */
    public function index(): bool|string
    {
        try {
            $info = $this->mode->where('uid','=',$this->userData['id'])->find();
            return success($info);
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 智慧果收发设置-保存
     * @return bool|string
     */
    public function update(): bool|string
    {
        try {
            $param = $this->request->param();
            $info = $this->mode->where('uid','=',$this->userData['id'])->find();
            if (!$info){
                $param['uid'] = $this->userData['id'];
                $param['time'] = time();
                $this->mode->insert($param);
            }else{
                $info->save($param);
            }
            return success();
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }
}